<!--
	作者：offline
	时间：2019-01-31
	描述：公告管理列表可查看编辑
-->
<template>
  <div class="m-view-noticeList m-window">
    <div class="m-condition" v-if="!noticeShow">
        <el-row :gutter="10">
        <el-col :span="2" :offset="14">
          <el-button type="primary" @click="search(1)" :disabled="btnDis">查询</el-button>
        </el-col>
        <el-col :span="2">
          <el-button type="primary" @click="add" :disabled="btnDis">新增</el-button>
        </el-col>
        <el-col :span="2">
          <el-button type="primary" @click="viewDetails()" :disabled="btnDis">查看</el-button>
        </el-col>
        <el-col :span="2">
          <el-button type="primary" @click="edit" :disabled="btnDis">编辑</el-button>
        </el-col>
        <el-col :span="2">
          <el-button type="primary" @click="del" :disabled="btnDis">删除</el-button>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-form
          :model="headerRuleForm"
          ref="headerRuleForm"
          label-width="70px"
          :inline-message="true"
          label-position="left"
        >
          <el-col :span="6">
            <el-form-item label="标题" class="rightItem">
              <el-input v-model="title" placeholder="请输入标题" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="发布日期" class="rightItem">
              <el-date-picker
                v-model="applySDate"
                type="date"
                placeholder="开始日期"
                :picker-options="po1"
                value-format="yyyy-MM-dd"
                :editable="false"
                :clearable="false"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-date-picker
              v-model="applyEDate"
              type="date"
              placeholder="结束日期"
              :picker-options="po2"
              value-format="yyyy-MM-dd"
              :editable="false"
              :clearable="false"
            ></el-date-picker>
          </el-col>
          <el-col :span="5">
            <el-form-item label="状态" class="rightItem">
              <el-select v-model="state" placeholder="状态" value-key="value" @change="stateChange">
                <el-option
                  v-for="item in stateOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
    </div>
    <div class="m-agTable m-bottom m-top2" v-show="!noticeShow">
      <agGridComponents
        ref="agGridComponent"
        :getGridOptions="gridOptions"
        :getColumnDefs="columnDefs"
      ></agGridComponents>
    </div>
    <div class="m-page" v-if="!noticeShow">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        @prev-click="handlePrevClick"
        @next-click="handleNextClick"
        :current-page="currentPage"
        :page-sizes="[30,50,100,150,200]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>

    <!-- 编辑弹窗 -->
    <el-dialog
      :title="diaTitle"
      :visible.sync="dialogVisible"
      v-if="dialogVisible"
      width="70%"
      :before-close="handleClose"
      v-dialogDrag
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      id="ls_noticeEdit"
      :inline-message="true"
    >
      <el-form
        :model="ruleForm"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
        :rules="rules"
      >
        <el-row>
          <el-col :span="18">
            <el-form-item label="标题" prop="title">
              <el-input v-model="ruleForm.title" placeholder="请输入标题(20字符)" clearable maxlength="20"  show-word-limit></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="9">
            <el-form-item label="类型" prop="type">
              <el-select v-model="ruleForm.type" placeholder="请选择类型">
                <el-option
                  v-for="item in typeOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="9">
            <el-form-item label="优先级" prop="priority">
              <el-select v-model="ruleForm.priority" placeholder="请选择优先级">
                <el-option
                  v-for="item in priorityOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="查看对象 " prop="traType">
              <el-radio-group v-model="ruleForm.traType">
                <el-radio :label="2">全部</el-radio>
                <el-radio :label="0">供应商</el-radio>
                <el-radio :label="1">内部用户</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="附件">
          <!-- <el-upload
            class="upload-demo"
            :action="baseUrl"
            :on-preview="handlePreview"
            :on-remove="handleRemove"
            :before-remove="beforeRemove"
            :limit="5"
            :file-list="files"
            :on-change="change"
            :data="userInfo"
            :onSuccess="uploadSuccess"
            :before-upload="beforeAvatarUpload"
            ref="upload"
          >
            <el-button size="small" type="primary">点击上传</el-button>
            <span
              slot="tip"
              class="el-upload__tip"
              style="padding-left:10px;"
            >只能上传.txt/.pdf/.doc/.docx/.xls/.xlsx文件，且不超过20MB</span>
          </el-upload>-->
          <lessoUploader
            :baseUrl="baseUrl"
            :userInfo="userInfo"
            :deleteBtn="true"
            @fileError="fileError"
            @fileExceed="fileExceed"
            @fileAdded="fileAdded"
            @fileRemoved="fileRemoved"
            @fileSuccess="fileSuccess"
            @overSize="overSizeHandler"
            :multiple="true"
            :limits="5"
            :maxSize="20971520"
            :allowDuplicateUploads="false"
            @deleteFile="onFileDelete"
          >
            <div slot="upload-btn">
              <div class="slot_btn">选择附件</div>
            </div>
          </lessoUploader>
          <div v-if="files.length>0">
            <div
              class="uploaded_files"
              v-for="(file,index) in files"
              :key="index"
              @mouseenter="file.iconShow=true"
              @mouseleave="file.iconShow=false"
            >
              <div class="name" :title="file.name">
                <i class="el-icon-document"></i>
                {{file.name}}
              </div>
              <span class="state_icon">
                <i class="el-icon-circle-check" style="color:#67c23a" v-show="!file.iconShow"></i>
                <i class="el-icon-close" v-show="file.iconShow" @click="deletedFile(file)"></i>
              </span>
            </div>
          </div>
        </el-form-item>
        <lesso-editor v-model="ruleForm.content" :options="editorOptions"></lesso-editor>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel" :disabled="disState">取消</el-button>
        <el-button @click="save('repeal')" :disabled="disState" type="primary" v-if="btnIf">保存</el-button>
        <el-button @click="publish" :disabled="disState" type="primary" v-if="btnIf">发布</el-button>
        <el-button @click="repeal" :disabled="disState" type="primary" v-if="!btnIf">撤销</el-button>
      </span>
    </el-dialog>
    <!-- 查看公告详情 -->
    <noticeDetailsComponent
      v-if="noticeShow"
      :setClickValue="clickValue"
      @cancelComponents="cancelComponents"
    ></noticeDetailsComponent>
  </div>
</template>

<script>
import _Api from "@/api";
import serviceTime from "@/public/serverTime.js";
import agGridComponents from "@/components/agGridComponents.js"
import waterfall from "async-es/waterfall";
import lessoUploader from 'lesso-file-upload/lessoUploader';
// import lessoDownload from 'lesso-file-download/lessoDownload'
import noticeDetailsComponent from "@/views/mine/noticeDetailsComponent.vue"
import Msg from "@/public/message.js";
import lessoEditor from 'lesso-vue-editor'
import constant from '@/public/constant'
import apienv from '@/api/env'


export default {
  data () {
    return {
      editorOptions: {
        userName: constant.employeeName,
        userId: constant.userId,
        uploadUrl: apienv[constant.appenv].srm + 'uploadFastdfs/',
      },
      rowSelection: 'multiple',
      upload_url: this.$uploadUrl,
      headerRuleForm: {},
      ruleForm: {
        traType: 2,
        priority: 0,
        content: '',
      },
      title: "",
      applySDate: "",
      applyEDate: "",
      po1: {
        disabledDate: this.disabledDate1
      },
      po2: {
        disabledDate: this.disabledDate2
      },
      state: 0,
      stateOptions: [
        { value: 0, label: "全部" },
        { value: 1, label: "未发布" },
        { value: 2, label: "已发布" }
      ],
      current: 0,
      textChange: 0,
      currentPage: 1,
      pageSize: 30,
      total: 0,
      gridOptions: {},
      columnDefs: [],
      btnDis: false,
      dialogVisible: false,
      typeOptions: [
        { label: "通知公告", value: 0 },
        { label: "制度公开", value: 1 }
      ],
      priorityOptions: [
        { label: "普通", value: 0 },
        { label: "紧急", value: 1 }
      ],
      rules: {
        title: [{
          required: true,
          trigger: "change",
          message: "标题不能为空"
        }],
        type: [{
          required: true,
          trigger: "change",
          message: "类型不能为空"
        }],
        content: [{
          required: true,
          trigger: "change"
        }]
      },
      disState: false,
      diaTitle: "",
      mode: "",// 状态 add:新增 edit:编辑
      operation: "",//操作
      //   文件上传地址
      baseUrl: apienv[constant.appenv].srm + 'uploadFastdfs/',
      userInfo: {
        userName: this.$global.user.employeeName,
        userId: this.$global.user.id,
        groupName: 'SRM'
      },
      attachmentList: [],//保存文件列表
      fileList: [],
      btnIf: true,
      clickState: "",
      files: [],
      directory: 'd:',
      noticeShow: false,
      clickValue: {}
    }
  },
  methods: {
    // 点击已上传文件钩子
    handlePreview (file) {
      //console.log(file);
    },
    // 文件移除钩子
    handleRemove (file, fileList) {
      //  if(this.attachmentList.length>0){
      //      for(var i in this.attachmentList) {
      //          if(this.attachmentList[i].uid==file.uid){
      //              this.attachmentList.splice(i,1)
      //          }
      //      }
      //  }
      //  console.log("已删除",this.attachmentList)
    },
    // 文件移除钱钩子
    beforeRemove (file, fileList) {
      const { status } = file
      if (status == 'success') {
        return new Promise((resolve, reject) => {
          this.$confirm("是否删除该附件？", "消息提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            distinguishCancelAndClose: true
          }).then(() => {
            if (file.id) {
              this.ruleForm.attachmentList.forEach((item, index) => {
                if (item.ID == file.id) {
                  this.attachmentList.push(item)
                  // that.ruleForm.attachmentList.splice(index, 1);
                }
              })
              resolve()
            } else {
              for (let k in this.attachmentList) {
                if (this.attachmentList[k].uid == file.uid) {
                  this.attachmentList.splice(k, 1)
                }
              }
              resolve()
            }
          }).catch(() => {
            reject()
          })
        })
      } else {
        return true
      }
      // return this.$confirm(`确定移除 ${ file.name }？`).catch(()=>{});
    },
    // 文件状态改变钩子
    change (file) {
      // this.upload_url="http://172.16.100.45:49231/srm/upload/file";
      this.upload_url = this.$uploadUrl;
    },
    // 文件上传成功钩子
    uploadSuccess (response, file, fileList) {
      if (response.code == 1) {
        Msg.showSuccessMsg("上传成功")
        //              console.log(response.rows[0]);
        //保存文件信息
        var obj = {
          creator: this.$global.user.loginName,
          creatorId: this.$global.user.id,
          resourceType: 1
        };
        obj.size = file.size;
        obj.url = response.rows[0].fileName;
        obj.name = file.name;
        obj.uid = file.uid;
        this.attachmentList.push(obj);
      } else {
        Msg.showErrorMsg("操作失败！");
        this.$refs.upload.clearFiles();
      }
    },
    // 文件上传前钩子
    beforeAvatarUpload (file) {
      var fileType = file.name.substring(file.name.lastIndexOf('.') + 1)
      if (fileType) {
        var fy = fileType.toLowerCase();
        if (fy != "txt" && fy != "pdf" && fy != "doc" && fy != "docx" && fy != "xls" && fy != "xlsx") {
          this.$message({
            message: '上传文件类型只支持.txt/.pdf/.doc/.docx/.xls/.xlsx ！',
            type: 'warning'
          })
          return false
        }
        const size = file.size / 1024 / 1024 < 20;
        if (!size) {
          this.$message({
            message: '上传模板大小不能超过 20MB!',
            type: 'warning'
          })
          return false
        }
      }
    },
    // 文件通过检查回调
    fileAdded (file) {
      let allFiles = [...this.files, ...this.attachmentList]
      if (allFiles.length > 4) {
        this.$message({
          message: '最多上传五个文件！',
          type: 'warning'
        })
        file.cancel();
      } else {
        for (var i in this.files) {
          if (this.files[i].md5 == file.md5) {
            this.$message({
              message: '请勿上传重复文件',
              type: 'warning'
            })
            file.cancel();
          }
        }
      }
    },
    // 删除文件
    onFileDelete (file, callback) {
      var that = this;
      this.$confirm("是否删除该附件？", "消息提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        distinguishCancelAndClose: true
      }).then(() => {
        // if (that.mode == "add") {
        callback(true);
        for (var i in that.attachmentList) {
          if (that.attachmentList[i].md5 == file.md5) {
            that.attachmentList.splice(i, 1);
          }
        }
        // }
      }).catch(() => { })
    },
    // 编辑时删除文件
    deletedFile (file, index) {
      this.$confirm("是否删除该附件？", "消息提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        distinguishCancelAndClose: true
      }).then(() => {
        let obj = {
          groupName: 'SRM',
          fileMd5: file.md5,
          uid: this.$global.user.id
        }
        _Api.deletedFastdfsFile(obj).then(({ data }) => {
          if (data.code == 200) {
            Msg.showSuccessMsg('文件已删除')
            this.files.splice(index, 1)
            this.attachmentList.push(file)
          } else {
            Msg.showErrorMsg(data.msg)
          }
        }).catch(err => {
          Msg.showErrorMsg(err.data.message)
        })
      })
    },
    // 文件上传成功回调
    fileSuccess (file, message, chunk) {
      if (message.code === 200) {
        var obj = {
          creator: this.$global.user.loginName,
          creatorId: this.$global.user.id,
          resourceType: 1
        };
        obj.size = file.size;
        obj.url = file.viewPath;
        obj.md5 = file.md5;
        obj.name = file.name;
        this.attachmentList.push(obj);
      }
    },

    fileRemoved (file, response) {
      if (response.code === 200) {
        for (let i = this.attachmentList.length - 1; i >= 0; i--) {
          if (this.attachmentList[i].md5 == file.md5)
            this.attachmentList.splice(i, 1);
        }
      }
    },
    // 文件超出大小回调
    overSizeHandler (file) { // 文件过大回调
      this.$message.warning("选择的文件大小不能超过20M")
    },
    onInvalidFile (file) {       //文件类型不合法
      this.$message.warning('文件类型不合法')
    },
    // 文件上传失败回调
    fileError (file, message, chunk) {
      message = JSON.parse(message)
      this.$message.error(message.msg);
    },
    //文件个数超出限制
    fileExceed (files, fileList) {
      this.$message.warning('上传文件个数超出限制,最多只能上传5个文件')
    },
    // 删除公告
    del () {
      var that = this;
      var row = this.$refs.agGridComponent.gridOptions.api.getSelectedRows();
      if (row.length <= 0) {
        this.$alert("提示：请选择需要删除的数据", {
          showClose: false,
          confirmButtonText: "确定",
          customClass: "alertPrompt"
        });
        return;
      }
      this.$confirm("是否删除该公告？", "消息提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        distinguishCancelAndClose: true
      }).then(() => {
        var id = '';
        for (var i = 0; i < row.length; i++) {
          id += row[i].ID + ',';
        }
        id = id.substr(0, id.length - 1);
        var obj = {
          ID: id,
          state: 0,
          modifyer: this.$global.user.loginName,
          modifyerId: this.$global.user.id
        }
        _Api.delNoticeInfo(obj).then(function (response) {
          var data = response.data;
          if (data.code == "1") {
            that.$message({
              message: "操作成功",
              type: "success"
            });
          } else {
            Msg.showErrorMsg(data.info);
          }
          that.search();
        }).catch((err) => {
          Msg.showErrorMsg(err.data.message);
        })
      }).catch(() => { })
    },
    // 编辑公告
    edit () {
      var row = this.$refs.agGridComponent.gridOptions.api.getSelectedRows();
      if (row.length <= 0) {
        this.$alert("提示：请选择需要编辑的数据！", {
          showClose: false,
          confirmButtonText: "确定",
          customClass: "alertPrompt"
        });
        return;
      }
      if (row.length > 1) {
        this.$alert("提示：只能选择单条进行编辑！", {
          showClose: false,
          confirmButtonText: "确定",
          customClass: "alertPrompt"
        });
        return;
      }
      if (row[0].state > 0)
        this.btnIf = false;
      else
        this.btnIf = true;
      this.mode = "edit";
      this.diaTitle = "编辑公告";
      for (var i in row[0].attachmentList) {
        var files = {};
        files.url = row[0].attachmentList[i].url;
        files.size = row[0].attachmentList[i].size;
        files.group = 'SRM';
        files.name = row[0].attachmentList[i].name;
        files.md5 = row[0].attachmentList[i].md5;
        files.ID = row[0].attachmentList[i].ID
        files.iconShow = false
        this.files.push(files);
      }
      this.ruleForm = row[0];
      this.dialogVisible = true;
    },
    // 撤销公告
    repeal () {
      var that = this;
      this.mode = "edit";
      this.$confirm("是否确认撤销该公告？", "消息提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        distinguishCancelAndClose: true
      }).then(() => {
        // that.operation = "repeal";
        that.save("repeal");
      }).catch(() => { })
    },
    // 发布公告
    publish () {
      // this.operation = "publish";
      this.save("publish");
    },
    // 保存公告信息
    save (state) {
      const { content } = this.ruleForm
      var that = this;
      let editorDoc = document.querySelector('#ls_noticeEdit')
      let text = editorDoc.querySelector('.w-e-text').innerText
      let img = editorDoc.querySelector('.w-e-text').getElementsByTagName('img')
      // 判断富文本内容是否为空   
      if (!content) {
        this.$message.error('公告内容不能为空')
        return
      } else {
        if (!text.trim() && img.length == 0) {
          this.$message.error('公告内容不能为空')
          return
        }
      }
      if (this.mode == "add") {
        waterfall([
          function getServiceTime (callback) {
            serviceTime.getServiceTime().then((serviceTime) => {
              var serTime = serviceTime.Format("yyyy-MM-dd HH:mm:ss");//绑定申请日期
              callback(null, true, serTime);
            });
          },
          function saveNoticeInfo (status, data, callback) {
            if (!status) return;
            that.$refs["ruleForm"].validate((valid) => {
              if (!valid) {
                return false;
              }
              if (!that.ruleForm.content) {
                that.$alert("提示：请填写内容！", {
                  showClose: false,
                  confirmButtonText: "确定",
                  customClass: "alertPrompt"
                });
                return false;
              }
              that.disState = true;
              that.ruleForm.creator = that.$global.user.loginName;
              that.ruleForm.creatorId = that.$global.user.id;
              that.ruleForm.releaseDate = data;
              that.ruleForm.releaser = that.$global.user.loginName;
              that.ruleForm.releaserId = that.$global.user.id;
              if (state == "publish")
                that.ruleForm.state = 1;
              else
                that.ruleForm.state = 0;//0 保存；1 发布
              that.ruleForm.attachmentList = that.attachmentList;
              _Api.saveNoticeInfo(that.ruleForm).then(function (response) {
                that.disState = false;
                var data = response.data;
                if (data.code == "1") {
                  that.$message({
                    message: "保存成功",
                    type: "success"
                  });
                  that.cancel();
                } else {
                  that.$alert(data.info, {
                    showClose: false,
                    confirmButton: "确定",
                    customClass: "alertFailure"
                  });
                }
              }).catch((err) => {
                that.$alert(err.data.message, {
                  showClose: false,
                  confirmButton: "确定",
                  customClass: "alertFailure"
                });
                that.disState = false;
              })
            })
          }
        ])
      } else {
        waterfall([
          function getServiceTime (callback) {
            serviceTime.getServiceTime().then((serviceTime) => {
              var serTime = serviceTime.Format("yyyy-MM-dd HH:mm:ss");//绑定申请日期
              callback(null, true, serTime);
            });
          },
          function saveNoticeInfo (status, data, callback) {
            if (!status) return;
            that.$refs["ruleForm"].validate((valid) => {
              if (!valid) {
                return false;
              }
              if (!that.ruleForm.content) {
                that.$alert("提示：请填写内容！", {
                  showClose: false,
                  confirmButtonText: "确定",
                  customClass: "alertPrompt"
                });
                return false;
              }
              that.disState = true;
              that.ruleForm.creator = that.$global.user.loginName;
              that.ruleForm.creatorId = that.$global.user.id;
              that.ruleForm.releaseDate = data;
              that.ruleForm.releaser = that.$global.user.loginName;
              that.ruleForm.releaserId = that.$global.user.id;
              if (state == "repeal")
                that.ruleForm.state = 0;//0 保存；1 发布
              else if (state == "publish")
                that.ruleForm.state = 1;
              that.ruleForm.attachmentList = that.attachmentList
              _Api.editNoticeInfo(that.ruleForm).then(function (response) {
                that.disState = false;
                var data = response.data;
                if (data.code == "1") {
                  that.$message({
                    message: "保存成功",
                    type: "success"
                  });
                  that.cancel();
                  //   if (that.attachmentList.length == 0)
                  //     that.cancel();
                  //   else
                  //     callback(null);
                } else {
                  that.$alert(data.info, {
                    showClose: false,
                    confirmButton: "确定",
                    customClass: "alertFailure"
                  });
                }
              }).catch((err) => {
                that.$alert(err.data.message, {
                  showClose: false,
                  confirmButton: "确定",
                  customClass: "alertFailure"
                });
                that.disState = false;
              })
            })
          },
          function saveAttachmentList (callback) {
            if (that.ruleForm) {
              for (var i in that.attachmentList) {
                that.attachmentList[i].resourceId = that.ruleForm.ID;
              }
              _Api.saveAttachment(that.attachmentList).then(function (response) {
                var data = response.data;
                if (data.code == "1") {
                  that.cancel();
                } else {
                  that.$alert(data.info, {
                    showClose: false,
                    confirmButton: "确定",
                    customClass: "alertFailure"
                  })
                }
              }).catch((err) => {
                that.$alert(err.data.message, {
                  showClose: false,
                  confirmButton: "确定",
                  customClass: "alertFailure"
                })
              })
            }
          }
        ])
      }
    },
    // 取消编辑
    cancel () {
      this.attachmentList = [];
      this.files = []
      this.dialogVisible = false;
      this.btnIf = true;
      this.search();
    },
    disabledDate1 (time) {
      if (this.applyEDate)
        return time.getTime() > new Date(this.applyEDate).getTime();
    },
    disabledDate2 (time) {
      if (this.applySDate)
        return time.getTime() < (new Date(this.applySDate).getTime() - 3600 * 1000 * 24);
    },
    stateChange (params) {
    },
    // 查询公告列表
    search (flag) {
      this.$refs.agGridComponent.loading = true;
      this.btnDis = true;
      var that = this;
      var obj = {};
      obj.geParams = {};
      obj.leParams = {};
      obj.eqParams = {};
      obj.likeParams = {};
      obj.size = this.pageSize;
      if (flag === 1)
        this.currentPage = 1;
      obj.current = this.currentPage;
      if (this.state)
        obj.eqParams.state = this.state - 1;
      if (this.title)
        obj.likeParams.title = this.title;
      if (this.applySDate)
        obj.geParams.releaseDate = this.applySDate + " 00:00:00";
      if (this.applyEDate)
        obj.leParams.releaseDate = this.applyEDate + " 23:59:59";
      this.$refs.agGridComponent.rowDataChange = false;
      _Api.getNoticeInfo(obj).then(function (response) {
        that.$refs.agGridComponent.loading = false;
        that.current = 0;
        that.textChange = 0;
        that.btnDis = false;
        var data = response.data;
        if (data.code == "1") {
          if (data.total > 0) {
            that.$refs.agGridComponent.gridOptions.api.setRowData(data.rows.splice(0));
            that.$refs.agGridComponent.rowDataChange = true;
            that.total = data.total;
            // that.currentPage = that.current;
          } else {
            that.$refs.agGridComponent.gridOptions.api.setRowData([]);
            that.total = 0;
            that.currentPage = 1;
          }
        } else {
          that.$alert(data.info, {
            showClose: false,
            confirmButton: "确定",
            customClass: "alertFailure"
          });
          that.$refs.agGridComponent.gridOptions.api.setRowData([]);
          that.total = 0;
          that.currentPage = 1;
        }
      }).catch((err) => {
        that.current = 0;
        that.textChange = 0;
        that.$alert(err.data.message, {
          showClose: false,
          confirmButton: "确定",
          customClass: "alertFailure"
        });
      })
    },
    // 查看公告详情
    viewDetails () {
      var row = this.$refs.agGridComponent.gridOptions.api.getSelectedRows();
      if (row.length <= 0) {
        this.$alert("提示：请选择需要查看的数据！", {
          showClose: false,
          confirmButtonText: "确定",
          customClass: "alertPrompt"
        });
        return;
      }
      if (row.length > 1) {
        this.$alert("提示：只能选择单行进行编辑！", {
          showClose: false,
          confirmButtonText: "确定",
          customClass: "alertPrompt"
        });
        return;
      }
      this.clickValue = row[0]
      this.noticeShow = true
      // console.log(row)
    },
    // 关闭详情页回调
    cancelComponents (msg) {
      if (msg) {
        this.noticeShow = false;
        this.search();
      }
    },
    // 新增公告
    add () {
      this.diaTitle = "新增公告";
      this.mode = "add";
      this.ruleForm = {
        traType: 2,
        priority: 0,
        content: ''
      };
      this.dialogVisible = true;
    },
    handleSizeChange (params) {
      this.currentPage = 1;
      this.pageSize = params;
      this.search();
    },
    handleCurrentChange (params) {
      if (this.textChange === 1 || this.current === 1)
        this.currentPage = 1;
      else
        this.currentPage = params;
      this.search();
    },
    handlePrevClick (params) {
      if (this.textChange === 1 || this.current === 1)
        this.currentPage = 1;
      else
        this.currentPage = params;
      // this.search();
    },
    handleNextClick (params) {
      if (this.textChange === 1 || this.current === 1)
        this.currentPage = 1;
      else
        this.currentPage = params;
      // this.search();
    },
    handleClose (done) {
      this.attachmentList = [];
      this.files = [];
      done();
      this.search();
      this.btnIf = true;
    }
  },
  mounted () {
    var that = this;
    this.userInfo.userName = this.$global.user.employeeName;
    this.userInfo.userId = this.$global.user.id;
    this.userInfo.groupName = 'SRM';
    // this.userInfo.userType = this.$global.user.userTypeId;
    serviceTime.getServiceTime().then((serviceTime) => {
      that.applyEDate = serviceTime.Format("yyyy-MM-dd");
      that.applySDate = new Date(serviceTime.getTime() - 604800000).Format('yyyy-MM-dd');
    })
  },
  components: {
    // lessoDownload,
    agGridComponents,
    // VueUeditorWrap,
    lessoUploader,
    noticeDetailsComponent,
    lessoEditor
  },
  beforeMount () {
    this.columnDefs = [
      { headerName: "标题", field: "title", checkboxSelection: true },
      { headerName: "创建人", field: "creator" },
      {        headerName: "创建日期", field: "createDate", cellRenderer: function (params) {
          if (params.value)
            return new Date(Date.parse(params.value.replace(/-/g, "/"))).Format("yyyy-MM-dd");
        }
      },
      { headerName: "发布人", field: "releaser" },
      {        headerName: "发布日期", field: "releaseDate", cellRenderer: function (params) {
          if (params.value)
            return new Date(Date.parse(params.value.replace(/-/g, "/"))).Format("yyyy-MM-dd");
        }
      },
      {        headerName: "优先级", field: "priority", cellRenderer: function (params) {
          if (params.value === 0)
            return '<span class="ag-icon">普通</span>'
          else if (params.value === 1)
            return '<span class="ag-icon">紧急</span>'
        }
      },
      {        headerName: "类型", field: "type", cellRenderer: function (params) {
          if (params.value === 0)
            return '<span class="ag-icon">通知公告</span>'
          else if(params.value === 1)
            return '<span class="ag-icon">制度公开</span>'
        }
      },
      {        headerName: "查看对象类型", field: "traType", cellRenderer: function (params) {
          if (params.value === 0)
            return '<span class="ag-icon">供应商</span>';
          else if (params.value === 1)
            return '<span class="ag-icon">内部用户</span>';
          else if (params.value === 2)
            return '<span class="ag-icon">全部</span>';
          else if (params.value === 3)
            return '<span class="ag-icon">指定对象</span>';
        }
      },
      {        headerName: "状态", field: "state", cellRenderer: function (params) {
          if (params.value === 0)
            return '<span class="ag-icon">未发布</span>';
          else if (params.value === 1)
            return '<span class="ag-icon">已发布</span>';
        }
      }
    ]
  },
  watch: {
    title (params) {
      //标题
      if (params)
        this.textChange = 1;
      else
        this.textChange = 0;
    },
    applySDate (params) {
      this.current = 1;
    },
    applyEDate (params) {
      this.current = 1;
    },
    state () {
      this.current = 1;
    }
  }
}
</script>

<style lang="less">
</style>